<?php
	include 'header.php';
	$id = isset($_GET['id']) && !empty($_GET['id']) ? $_GET['id'] : '0';
	
	
	if($id <= 0){
		$stmt = $pdo->prepare('select max(id) maxid from kp_news');
		$stmt->execute();
		$arr = $stmt->fetch(PDO::FETCH_ASSOC);
		if(!empty($arr)){
			$id = $arr['maxid'];
		}
		//进行查询
		$stmt = $pdo->prepare('select id,uid,newdate,title,content,(select id from kp_news where id > ? order by id asc limit 1) upid,(select id from kp_news where id < ? order by id desc limit 1) downid from kp_news order by id desc limit 1');
		$stmt->execute(array($id,$id));
	}else{
		$stmt = $pdo->prepare('select id,uid,newdate,title,content,(select id from kp_news where id > ? order by id asc limit 1) upid,(select id from kp_news where id < ? order by id desc limit 1) downid from kp_news where id = ? order by id desc limit 1');
		$stmt->execute(array($id,$id,$id));
	}
	
	
	$arrNew = $stmt->fetch(PDO::FETCH_ASSOC);
//	print_r($arrNew);
	
?>
<!DOCTYPE html>
<html lang="zh">
	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<meta http-equiv="X-UA-Compatible" content="ie=edge" />
		<link rel="stylesheet" type="text/css" href="css/news.css"/>
		<title>资讯页</title>
	</head>
	<body>
		<div id="news">
			<div class="title">
				<h2>您的位置: 资讯</h2>
			</div>
			<?php 
			if(!empty($arrNew)){
			?>
			
			<div class="new">
				<!--头-->
				<div class="newt">
					<h3><?php echo $arrNew['title'];  ?></h3>
					发布时间:<?php echo $arrNew['newdate'];  ?>
				</div>
				<!--中-->
				<div class="newm">
					<?php echo $arrNew['content'];  ?>
				</div>
				<!--底-->
				<div class="newb">
					<ul>

						<?php if(!empty($arrNew['upid'])){ ?>
						<a href="news.php?id=<?php echo $arrNew['upid']; ?>"><li>&lt;&lt;上一条</li></a>
						<?php } ?>
						<?php if(!empty($arrNew['downid'])){ ?>
						<a href="news.php?id=<?php echo $arrNew['downid']; ?>"><li>下一条&gt;&gt;</li></a>
						<?php } ?>
					</ul>
					  
				</div>			
			</div>
			<?php 
			}
			?>
		</div>
		<?php include 'bottom.php'; ?>
	</body>
</html>